/*
 * Copyright (c) 2022. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.pobing.service.impl;

import com.pobing.grpc.lib.hello.HelloRequest;
import com.pobing.grpc.lib.hello.HelloResponse;
import com.pobing.grpc.lib.move.MoveRequest;
import com.pobing.grpc.lib.move.MoveResponse;
import com.pobing.grpc.lib.move.MoveServiceGrpc;
import com.pobing.grpc.lib.move.MoveServiceGrpc.MoveServiceImplBase;
import com.pobing.service.MoveService;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xfworld
 * @since create on 2022-05-17.
 **/
@Service
public class MoveServiceImpl extends MoveServiceImplBase implements MoveService {

    @GrpcClient("moveSampleServer")
    private MoveServiceGrpc.MoveServiceBlockingStub moveServiceBlockingStub;

    @Override
    public Map<String, String> moveData(String name) {
        MoveResponse response = moveServiceBlockingStub.sayMove(MoveRequest.newBuilder().setName(name).build());
        Map<String, String> map = new HashMap<>(2);
        map.put("code", response.getCode());
        map.put("msg", response.getMessage());
        return map;
    }
}
